﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Imageo.bintje;
using log4net;
using System.Threading;

namespace Imageo.ui
{
    public partial class ChangePassword : System.Web.UI.Page
    {
        private static readonly ILog log = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

        protected void Page_Load(object sender, EventArgs e)
        {
            bintje.imageoSession currentSession = Session["BintjeSession"] as imageoSession;
            if (currentSession == null) Response.Redirect("~/UI/ErrorLoginFirst.aspx");
        }

        protected void btnChangePassword_Click(object sender, EventArgs e)
        {
            try
            {
                bintje.imageoSession currentSession = Session["BintjeSession"] as imageoSession;
                ServiceAPI service = new ServiceAPI();

                if (log.IsErrorEnabled) log.Debug("Calling: service.resendPassword(req)");
                userResponse response = ServiceHelper.HandleBintjeErrors(this, service.changePassword(currentSession, txtPassOld.Text, txtPass1.Text));

                tblDone.Visible = true;
                tblChange.Visible = false;
            }
            catch (ThreadAbortException) { }
            catch (Exception exc)
            {
                if (log.IsErrorEnabled)
                {
                    log.Error(exc.Source + " - " + exc.Message);
                }
                Response.Redirect("~/UI/ErrorGeneric.aspx");
            }
        }
    }
}
